﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jy123.BLL.Public;

namespace Jy123.BLL.Guess
{
    public class GuessList
    {   
        /// <summary>
        /// 获取竞猜分页列表
        /// </summary>
        /// <param name="FUser">发布用户ID</param>
        /// <param name="currentpage">当前页</param>
        /// <param name="pageSize">分页尺寸</param>
        /// <param name="field">字段</param>
        /// <param name="sortField">排序语句(比如OverTime Desc)</param>
        /// <returns>竞猜分页列表</returns>
        public List<Jy123.Model.User_Guess_Main> getGuessList(string strFilter, int currentpage, int pageSize, string field, string sortField, out List<int?> count)
        {
            Jy123.Model.MPagination mPagination = new Jy123.Model.MPagination();

            mPagination.Tables = "User_Guess_Main";
            mPagination.PrimaryKey = "ID";
            mPagination.Fields = field;
            mPagination.CurrentPage = currentpage;
            mPagination.Filter = strFilter;
            mPagination.PageSize = pageSize;
            mPagination.Sort = sortField;
            mPagination.Group = string.Empty;
            DataSet ds = Pagination.GetList(mPagination);
            
            Pagination.GetList(mPagination, out count);
            List<Jy123.Model.User_Guess_Main> modelList = new BLL.User_Guess_Main().DataTableToList(ds.Tables[0]);
            return modelList;
        }

        /// <summary>
        /// 获取竞猜倍率形式
        /// </summary>
        /// <param name="Multiple">竞猜倍率</param>
        /// <returns>竞猜倍率String</returns>
        public string getGuessMultiple(int Multiple)
        {
            StringBuilder sb = new StringBuilder();

            if (Multiple == 0)
            {
                sb.Append("均分池里积分");
            }
            else
            {
                sb.AppendFormat("{0}倍", Multiple);
            }

            return sb.ToString();
        }

        /// <summary>
        /// 获取回复数
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public string getReviewCount(int ID)
        {
            StringBuilder sbHtml = new StringBuilder();
            string count = new Jy123.BLL.Guess.GuessSql().GetReviewCount(ID);

            if (new Jy123.BLL.Guess.GuessSql().StatExists("User_Guess_Review", ID))  //是否有回复
            {
                sbHtml.AppendFormat("评论({0})", count);
                return sbHtml.ToString();
            }
            else
            {
                sbHtml.Append("评论(0)");
                return sbHtml.ToString();
            }
        }

        /// <summary>
        /// 获取竞猜参与统计
        /// </summary>
        /// <returns>返回人数/份数string</returns>
        public string getGuessCount(int ID)
        {
            if (new Jy123.BLL.Guess.GuessSql().StatExists("User_Guess_Stat", ID))
            {

                return new Jy123.BLL.Guess.GuessSql().GetStatHtml(ID);

            }
            else
            {

                return "0人(0份)";
            }
        }

    }
}
